<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>

    <script>
        $(function () {
            //引入文本编辑器插件ckeditor
            var ck = CKEDITOR.replace('editor');

            $(".inputBtn").click(function () {

                //1.清空模态框数据
                $("#editForm input,#editForm select").val("");
                $("#coverUrl").attr("src", "");


                //获取绑定的json
                var json = $(this).data('json');

                // 回显
                if (json) {
                    //回显id隐藏域
                    $("input[name='id']").val(json.id);
                    //标题
                    $("input[name='title']").val(json.title);
                    //封面
                    $("#coverUrl").attr("src", json.coverUrl);
                    $("input[name='coverUrl']").val(json.coverUrl);

                    //状态
                    $("select[name='state']").val(json.state);
                    //设置到文本编辑器中
                    ck.setData(json.content);


                } else {
                    //保存时 清除富文本编辑器
                    ck.setData("");
                }

                //回显模态框
                $("#inputModal").modal("show");


                //保存按钮
                $("#editForm").ajaxForm(function (data) {
                    reload();
                })

                $(".btn-submit").click(function () {
                    console.log($("#coverUrl").val());
                    //1.文本编辑器中获取内容
                    var content = ck.getData();
                    //2.设置form表单textarea
                    $("textarea[name='content']").val(content);
                    $("#editForm").submit();
                });

            });
        });
    </script>


</head>
<body>

<div class="container " style="margin-top: 20px">
   <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#assign currentMenu="dailyPaper"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">日报管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/dailyPaper/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入日志标题">
                </div>
                <button id="btn_query" class="btn btn-primary">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a class="btn btn-success  btn-input inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>日报标题</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td><img src="${entity.coverUrl}" style="width: 30px"/></td>
                        <td>${entity.title}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a class="btn btn-info btn-xs btn-input inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span>修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
           <#include "../common/page.ftl"/>
        </div>
    </div>
</div>



<#--修改模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">日报编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/dailyPaper/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="100%"/>
                            <input type="file" class="form-control" name="file">
                            <input type="hidden" class="form-control" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" autocomplete="off" name="state">
                                <option value="0">普通</option>
                                <option value="1">热门</option>
                                <option value="-1">禁用</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="content" id="editor" rows="10" cols="80">
                        </textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>